<?
	if(isset($_GET['cid'])){
		$cid = intval($_GET['cid']);
	}else{$cid = 0;}
	
	if(isset($_GET['ttid'])){
		$ttid = intval($_GET['ttid']);
	}
	
	if(isset($_GET['keyword'])){
		$keyword = $_GET['keyword'];
	}
	
	
	if($cid == 0){
		$sql = "SELECT * FROM ".$prefix."raovat WHERE 1";
	}else{
		$sql = "SELECT * FROM ".$prefix."raovat WHERE rv_loairaovat = '".$cid."'";
	}
	$sql .= " AND rv_hienthi = 1";
	
	/////////TIM KIEM THEO TINH THANH ///////////
	if(isset($ttid) && ($ttid != "") ){
		$sql .= " AND rv_tinhthanh = '".$ttid."'";
	}
	
	if(isset($keyword) && ($keyword != "") ){
		$sql .= " AND (rv_tieude like '%".$keyword."%' OR rv_mota like '%".$keyword."%' OR rv_chitiet like '%".$keyword."%')";
	}
	
	if(isset($_GET['sid'])){
		$sid = intval($_GET['sid']);
		if($sid == 1){
			$sql .= " ORDER BY rv_id DESC";
		}else if($sid == 2){
			$sql .= " ORDER BY rv_id ASC";
		}else{
			$sql = $sql;
		}
	}
	
	//Paging
	$pp=10; 
	$parr=array();
	$parr=paging($sql,$pp);
	$page=$parr[0];
	$limitvalue=$parr[1];
	$numofpages=$parr[2];
	$sql.=" LIMIT $limitvalue, $pp";
	//
	$rs = $db->query($sql);
?>

<script language="javascript">
	function funSort(id,cid,p){
		window.location = '<?=$root?>/?mod=raovat&cid=' + cid + '&sid=' + id + '&p=' + p;
	}
</script>
<div id="filtersDescription">
	<div class="corner-round-04-body"> 
        
        <ul id="descriptionBar" style="margin:0px;">
            <li style="float:left;margin:0px;line-height:20px;">Tìm thấy <b class="highline"><?=$db->num_rows($rs)?></b> tin rao vặt</li>

            <li style="float:right;margin:0px;line-height:20px;" id="menuContainer">
              Sắp xếp theo:
			  <select name="sort" style="width:120px;" onchange="funSort(this.value,'<?=$cid?>','<?=$p?>');">
			  	<option value="0" <? if($sid == 0){?> selected="selected" <? }?>>-- Tất cả --</option>
				<option value="1" <? if($sid == 1){?> selected="selected" <? }?>>Mới dần</option>
				<option value="2" <? if($sid == 2){?> selected="selected" <? }?>>Cũ dần</option>
			  </select>
			  </li>                       
        </ul>
        <br class="clearBoth" style="font-size:0pt;"/> 
        <p></p>        
                      
    </div> 
</div> 

     
                         
            
<!-- Product List { -->
<div id="product-list">
    <div id="product-list-header">       
        <div class="product-col product-col-name">
            <p>Tiêu đề rao vặt</p>

        </div>
        <div class="product-col product-col-price">
            <p>Nơi đăng</p>
        </div>
        <div class="product-col product-col-region">
            <p>Ngày đăng</p>
        </div>
    </div>

    <div style="clear:both;height:4px;font-size:0pt;"></div>
    <div id="product-list-body">
        <div class="product-list-body"> 
            
                <table width="100%" cellpadding="0" cellspacing="0" id="products-items">

			<?
				$st =0;
				 while($row = $db->fetch_array($rs)){
				 $st++;
				 $rv_id = $row[rv_id];
				 $rv_loairaovat = $row[rv_loairaovat];
				 $rv_tieude = $myString->unQuote(stripslashes($row[rv_tieude]));
				 $rv_mota = $myString->unQuote(stripslashes($row[rv_mota]));
				 $rv_anhthehien = $PathThumbFile . $row[rv_anhthehien];
				 $rv_nguoidang = $row[rv_nguoidang];
				 $rv_nguoidang_ten = tenNguoiDung($row[rv_nguoidang]);
				 $rv_quocgia = layQuocGia($row[rv_quocgia]);
				 $rv_tinhthanh = layTinhThanh($row[rv_tinhthanh]);
				 $rv_thoigian = format_date($row[rv_thoigian]);
				 $rv_thoigiandang = $row[rv_thoigiandang];
				 $rv_chitiet = $myString->unQuote(stripslashes($row[rv_chitiet]));
				 $rv_solanxem = $row[rv_solanxem];
				 $rv_xemgannhat = format_date_time($row[rv_xemgannhat]);
				 $rv_hienthi = $row[rv_hienthi];
				 $rv_vip = $row[rv_vip];
				 
			?>
                    <tr>
                        <td class="col-picture">
                            <p> 
                                <a title="<?=$rv_tieude?>" href="<?=$root?>/chi-tiet-rao-vat/<?=$rv_id?>/<?=$myString->vietdecode($rv_tieude)?>" class="tips product-name">
                                    <img width="100px" style="vertical-align:middle" alt="<?=$rv_tieude?>" src="<?=$root?>/<?=$rv_anhthehien?>" onerror="this.src='<?=$root?>/themes/images/noimg.jpg';"/>
                                </a>
                            </p> 
                        </td>
                        <td class="col-name">
                            <h1>

                                <a href="<?=$root?>/chi-tiet-rao-vat/<?=$rv_id?>/<?=$myString->vietdecode($rv_tieude)?>" class="product-name" title="<?=$rv_tieude?>"><?=$rv_tieude?></a>
								<?
								if($rv_vip == 1){
								?>
								<blink><font color="red"><b>VIP</b></font></blink>
								<? } ?>
                            </h1> 
                            <p class="truncate" style="text-align:left;">
                                <?=$myString->cutString2($rv_mota,90)?>
                            </p>        
                            <p style="padding-bottom:5px;">                                
                                Người đăng: <a href="<?=$root?>/shop-<?=$rv_nguoidang?>/<?=tenNguoiDung2($rv_nguoidang)?>" class="popup-profile"> <?=banned($rv_nguoidang,$rv_nguoidang_ten)?></a>      
                            </p> 
                            <p style="font-size:8pt;color:Gray;">

                                <?=$rv_xemgannhat?> | Xem: <?=$rv_solanxem?>
                            </p>
                        </td>
                        <td class="col-price">
                            <p>
                                <?=$rv_tinhthanh?>                                        
                            </p>
                        </td>
                        <td class="col-region">
                            <p>

                                <?=$rv_thoigian?>
                            </p>
                        </td>
                    </tr>  
                <? if($st != $db->num_rows($rs)){ ?>
                    <tr>
                        <td colspan="4" style="border-bottom:solid 1px #CCCCCC;height:1px;font-size:0pt;"></td>
                    </tr>                       
				<? } ?>
           <? } 
		   		if($db->num_rows($rs) == 0){
		   ?>     

 				<tr>
					<td align="left" style="padding-left:10px;">Không có tin rao vặt nào !</td>
				</tr>
           <? } ?>     
                </table> 
                
        </div> 
    </div>
    <div id="product-list-footer"></div>
</div>

<!-- Paging { -->


<div id="paging">
    <div class="corner-round-01-body" style="text-align:right">            
		<p align="center" class="font">
		<?php echo page_div( "".$root."/?mod=raovat&sid=".$sid."&cid=".$cid."&p=%d_pg", "10", ceil ( $numofpages ), $page ); ?>
		</p>
    </div>
</div>   

<!-- } Paging -->

<!-- } Product List -->